package com.yidu.InventoryManagement.service.impl;

import com.yidu.InventoryManagement.entity.Cash;
import com.yidu.InventoryManagement.entity.CashStock;
import com.yidu.InventoryManagement.mapper.CashStockMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 梁俊
 * @date 2022/12/7
 * &@version 1.0
 */
@Service
public class CashStockServiceImpl implements com.yidu.InventoryManagement.service.CashStockService {
    @Resource
    private CashStockMapper cashStockMapper;

    /**
     * 分页模糊查现金库存
     * @return Map
     */
    @Override
    public List<CashStock> selectCashStock(int page, int limit, String accountName, String date) {
        Map map=new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("accountName",accountName);
        map.put("DATE",date);
        return cashStockMapper.selectCashStock(map);
    }

    /**
     * 根据名字和时间查询现金库存行数
     * @param accountName 名字
     * @param date 时间
     * @return
     */
    @Override
    public int selectCount(String accountName, String date) {
        return cashStockMapper.selectCount(accountName, date);
    }

    /**
     * 查询现金库存id是否为空
     * @return
     */
    @Override
    public int selectCashStockIdd() {
        return cashStockMapper.selectCashStockIdd();
    }

    /**
     * 多个删除
     * @param cashStockId 现金库存id
     * @return
     */
    @Override
    public int deleteCashStock(String cashStockId) {
        //将id转为数据
        String[] split = cashStockId.split(",");
        //创建存放id的集合
        ArrayList<Object> equityDataIdList = new ArrayList<Object>();
        for (String id : split) {
            //将id存入集合
            equityDataIdList.add(id);
        }
        return cashStockMapper.deleteCashStock(equityDataIdList);
    }


    /**
     * 添加现金库存表
     * @param cashStock
     * @return
     */
    @Override
    public int insertCashStock(CashStock cashStock) {
        return cashStockMapper.insertCashStock(cashStock);
    }


    /**
     * 取现金库存最大的id
     * @return 最大id
     */
    @Override
    public String selectDa() {
        return cashStockMapper.selectDa();
    }

    /**
     * 根据id查询现金库存数据
     */
    @Override
    public CashStock selectCashStockId(String cashStockId) {
        return cashStockMapper.selectCashStockId(cashStockId);
    }

    /**
     * 根据id修改现金库存数据
     */
    @Override
    public int updateCashStock(CashStock cashStock) {
        return cashStockMapper.updateCashStock(cashStock);
    }


    /**
     * 查询现金账户ID
     */
    @Override
    public List<Cash> selectCash(int page, int limit) {
        Map map=new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        return cashStockMapper.selectCash(map);
    }


    /**
     * 下拉表格查询现金账户的行数
     */
    @Override
    public int selectCashCount() {
        return cashStockMapper.selectCashCount();
    }


}

